//
//  LCProductVC.m
//  stone-story
//
//  Created by dodo liu on 12-9-24.
//  Copyright (c) 2012年 liu dodo. All rights reserved.
//

#import "LCProductVC.h"

@interface LCProductVC ()

@end

@implementation LCProductVC
@synthesize photos = _photos;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [ self addNavBarRightBtn];
    
	// Do any additional setup after loading the view.
}

- (void)addNavBarRightBtn
{
    UIBarButtonItem *btn_1 = [[UIBarButtonItem alloc] initWithTitle:@"下载管理"   
                                                                 style:UIBarButtonItemStyleBordered   
                                                                target:self   
                                                                action:@selector(btn_1_click)];  
    
    UIBarButtonItem *btn_2 = [[UIBarButtonItem alloc] initWithTitle:@"下载"
                                                                 style:UIBarButtonItemStyleBordered 
                                                                target:self action:@selector(btn_2_click)];
    UIToolbar *tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 105, 45)];
    
    tools.barStyle=UIBarStyleBlack;
    NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2];
    
    [buttons addObject:btn_1];
    [buttons addObject:btn_2];
    [tools setItems:buttons animated:NO];
    self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc] initWithCustomView:tools]; 
    
}

- (void)btn_1_click
{
    // Browser
	NSMutableArray *photos = [[NSMutableArray alloc] init];
    MWPhoto *photo;
	
            photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo1l" ofType:@"jpg"]];
            photo.caption = @"Grotto of the Madonna";
			[photos addObject:photo];
            photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo2l" ofType:@"jpg"]];
            photo.caption = @"The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England.";
			[photos addObject:photo];
            photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo3l" ofType:@"jpg"]];
            photo.caption = @"York Floods";
			[photos addObject:photo];
            photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo4l" ofType:@"jpg"]];
            photo.caption = @"Campervan";
			[photos addObject:photo];
		    self.photos = photos;
	
	// Create browser
	MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    browser.displayActionButton = YES;
    //browser.wantsFullScreenLayout = NO;
    //[browser setInitialPageIndex:2];
    
    // Show
   
        [self.navigationController pushViewController:browser animated:YES];
  
}

- (NSMutableArray*)getAllPhotos
{
    
    NSString *filePath =[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/photos"];
    NSError *error = nil;
    NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filePath error:&error];
    NSMutableArray *fileNames;//=[[NSMutableArray alloc]init];
    NSLog(@"%@", dirContents);
    if ( ! error) {
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self ENDSWITH '.jpg'"];
        NSArray *imagesOnly = [dirContents filteredArrayUsingPredicate:predicate];
        fileNames = [NSMutableArray arrayWithArray:imagesOnly];
    }
    
   // count = [fileNames count];  //得到数量多少
    return fileNames;
}
#pragma mark - MWPhotoBrowserDelegate

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return _photos.count;
}

- (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < _photos.count)
        return [_photos objectAtIndex:index];
    return nil;
}



- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

@end
